<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入
* iclient-plot-leaflet (https://iclient.supermap.io/web/libs/plotting/leaflet/11.1.0/iclient-plot-leaflet.min.js)
*********************************************************************-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_iPortalQueryMyResources"></title>
    <style>
    .container-wrap {
        padding-left: 200px!important;
    }
    .gallery-item {
        margin-bottom: 30px;
    }
    .gallery-item-border {
        border: 1px solid #dadada;
        -webkit-box-shadow: 0px 2px 3px #dcdcdc;
        box-shadow: 0px 2px 3px #dcdcdc;
        background: white;
    }
    .gallery-item-img {
        height: 170px !important;
        width: 262px !important;
    }
    .resourcesDetails {
        height: 21px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 14px !important;
        color: #7c7c7c;
    }
    .title-checkbox-container p{
        max-width: 160px;
        float: left;
    }
    .title-checkbox-container input{
        float: right;
    }
    .operate-btn-container , .title-checkbox-container{
        width: 100%;
        height: 33px;
        padding: 0 17px;
    }
    .operate-btn-container a:nth-child(1){
        float: left;
    }
    .operate-btn-container a:nth-child(2){
        float: right;
    }
    #plottingPanel {
        float: left;
        background: #ffffff;
        width: 250px;
        height: 100%;
        border: 1px solid #3473b7;
    }
    .datagrid-cell {
        word-break: break-all;
        white-space: normal!important;
    }
    .tabs-container ,.tabs-panels,.panel-body{
        height: auto!important;
    }
    .panel-title {
        margin-top: 0!important;
        margin-bottom: 0!important;
        font-size: 16px!important;
        color: inherit!important;
    }
    .input-group-addon {
        cursor: pointer;
    }
    .tab-content {
        max-height: 500px;
        overflow-y: auto;
    }
    .tab-pane {
        margin-top: 12px;
    }
    .choose {
        display: block;
        margin: 12px 0;
    }
    </style>
</head>
<body style=" margin: 0;overflow: auto;background: #F2F2F2;width: 100%;height:100%;position: absolute;top: 0;">
    <!-- 删除资源模态框（Modal） -->
    <div class="modal fade" tabindex="-1" role="dialog" id="deleteModel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" data-i18n="resources.title_delete_resources"></h4>
                </div>
                <div class="modal-body">
                    <p data-i18n="resources.title_confirm_delete_resources"></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" data-i18n="resources.text_close"></button>
                    <button type="button" class="btn btn-primary" onclick="requestDeleteUrl()" data-i18n="resources.text_confirm"></button>
                </div>
            </div>
        </div>
    </div>
    <!-- 共享资源模态框（Modal） -->
    <div class="modal fade" id="shareModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="removeUser()"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" data-i18n="resources.title_share_setting"></h4>
                    </div>
                </div>
                    <table class="table table-bordered col-md-6">
                        <tbody>
                        <!--共享设置-->
                        <tr>
                            <td>
                                <div class="col-md-10 col-md-offset-1">
                                    <form class="form-horizontal">
                                        <fieldset>
                                                <ul class="nav nav-tabs" role="tablist">
                                                    <li role="presentation" class="active">
                                                        <a href="#public" aria-controls="public" role="tab" data-toggle="tab" data-i18n="resources.title_iPortalQueryResourcesPublic"></a>
                                                    </li>
                                                    <li role="presentation">
                                                        <a href="#group" aria-controls="group" role="tab" data-toggle="tab" data-i18n="resources.title_iPortalQueryResourcesGroup"></a>
                                                    </li>
                                                    <li role="presentation">
                                                        <a href="#department" aria-controls="department" role="tab" data-toggle="tab" data-i18n="resources.title_iPortalQueryResourcesDepartment"></a>
                                                    </li>
                                                    <li role="presentation">
                                                        <a href="#user" aria-controls="user" role="tab" data-toggle="tab" data-i18n="resources.title_iPortalQueryResourcesUser"></a>
                                                    </li>
                                                </ul>
                                                <div class="tab-content">
                                                    <div role="tabpanel" class="tab-pane active" id="public">
                                                        
                                                    </div>
                                                    <div role="tabpanel" class="tab-pane" id="group">
                                                        <table border="1" bordercolor="black" width="100%">
                                                            <thead id="group_thead">
                                                                
                                                            </thead>
                                                            <tbody id="group_tbody">
                                                                
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                    <div role="tabpanel" class="tab-pane" id="user">
                                                        <div class="input-group" style="margin-top: 12px;width: 100%;">
                                                            <input type="text" class="form-control" data-i18n="[placeholder]resources.text_input_user_name" id="add-user-val">
                                                            <span class="input-group-addon" onclick="searchUser()" data-i18n="resources.btn_add"></span>
                                                        </div>
                                                        <span data-i18n="resources.text_choose_user" class="choose"></span>
                                                        <table border="1" bordercolor="black" width="100%">
                                                            <thead id="user_thead">
                                                                
                                                            </thead>
                                                            <tbody id="user_tbody">
                                                                
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                    <div role="tabpanel" class="tab-pane" id="department">
                                                        <span data-i18n="resources.text_choose_department" class="choose"></span>
                                                        <table border="1" bordercolor="black" width="100%">
                                                            <thead id="department_thead">
                                                                
                                                            </thead>
                                                            <tbody id="department_tbody">
                                                                
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                        </fieldset>
                                    </form>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" data-i18n="resources.text_close" onclick="removeUser()">
                    </button>
                    <button type="button" class="btn btn-primary" onclick="requestShareUrl()" data-i18n="resources.btn_save">
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!-- 详情 属性面板Dom -->
    <div id="plottingPanel">
        <div class="easyui-panel" style="position:absolute;top:0px;bottom:0px;left:0px;right:0px;padding:5px; width: 100%;">
            <div class="easyui-tabs" style="width: 100%;height: 100%" id="edit-and-detail-plot">
                <div id="iPortalDetailPanel" data-i18n="[title]resources.text_detailPanel" style="overflow: hidden"></div>
                <div id="plotPanel" data-i18n="[title]resources.text_attributePanel" style="overflow: hidden"></div>
            </div>
        </div>
    </div>
    <!-- 资源过滤 and 资源展示 -->
    <div style="margin-bottom: 100px">
        <div id="toolbar" class="panel panel-primary" style="position: absolute;top: 10px;right: 70px;text-align: center;z-index: 800;border-radius: 4px;">
            <div class='panel-heading' id="panelheading">
                <h5 class='panel-title text-center' data-i18n="resources.title_iPortalQueryMyResources"></h5>
            </div>
            <div class='panel-body content' id="panelbodycontent">
                <!-- 资源类型选择 -->
                <div class='input-group' style="width: 220px">
                    <span class='input-group-addon' data-i18n="resources.title_iPortalQueryResourcesType"></span>
                    <select class='form-control' id='typeSelect' onchange="onSelectResourcesType()">
                        <option value="MAP" data-i18n="resources.title_iPortalQueryResourcesMap"></option>
                        <option value="SERVICE" data-i18n="resources.title_iPortalQueryResourcesService"></option>
                        <option value="SCENE" data-i18n="resources.title_iPortalQueryResourcesScene"></option>
                        <option value="DATA" data-i18n="resources.title_iPortalQueryResourcesData"></option>
                        <option value="INSIGHTS_WORKSPACE" data-i18n="resources.title_iPortalQueryResourcesInsights"></option>
                        <option value="MAP_DASHBOARD" data-i18n="resources.title_iPortalQueryResourcesDashboards"></option>
                    </select>
                </div>
            </div>
        </div>
        <br />
        <div class="container container-wrap">
            <div class="col-md-10">
                <div class="row">
                    <div class="col-md-12">
                        <div class="operate-list">
                            <input type='button' class="btn btn-default" onclick="deleteResource()" data-i18n="[value]resources.text_input_value_delete"/>
                            <input type='button' class="btn btn-default" onclick="shareResource()" data-i18n="[value]resources.title_share_setting"/>
                        </div>
                        <!--所有资源的承载DIV-->
                        <div class="row" id="resourcesList">
                            <!--单个资源数据的可视化承载DIV 添加在此位置中-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<script type="text/javascript" include="jquery,bootstrap,plottingPanel,widgets" src="../js/include-web.js"></script>
<script type="text/javascript" include="iclient-plot-leaflet" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript" include="iPortalStylePanel" src="../js/plottingPanel/PlottingPanel.Include.js"></script>
<script>
    //iportal的URL地址 或根据情况添加自己的本地iportal地址：http://localhost:8091/iportal
    var iPortalUrl = "https://iportal.supermap.io/iportal";
    var token = window.iportalToken;
    //默认请求资源类型
    var resourceType = "MAP";
    //全局变量，承载请求后，一共有多少页数
    var queryParams = new L.supermap.iPortalQueryParam({
        resourceType: resourceType,
        pageSize: 15,
        currentPage: 1,
        searchType:'MY_RES'
    });
    //资源查询初始化工作
    var iPortal;
    var isShowLogin = true;
    var deleteIds = [];//批量删除id
    var shareIds = [];//批量共享设置id
    var itemData = {};//某条资源的详细信息
    //公开权限共享实体参数
    var publicSettingEntity = {
        "permissionType": "",
        "entityType": "USER",
        "entityName": "GUEST",
        "entityId": null,
        "authorizeList": []
    }
    // 用户权限共享实体参数
    var usersSettingEntities = [];
    // 部门权限共享实体参数
    var departmentSettingEntities = [];
    // 群组权限共享实体参数
    var groupsSettingEntities = [];
    // 用户的登陆信息对象
    var userStateObj = {};
    // 群组列表
    var groupList = [];
    $(document).ready(function () {
        generatePortalToken();
    });
    // 申请，注册token并查询
    function generatePortalToken() {
        var serverInfo = new L.supermap.ServerInfo(L.supermap.ServerType.IPORTAL, {
            server: iPortalUrl
        });

        L.supermap.SecurityManager.registerServers([serverInfo]);
        L.supermap.SecurityManager.destroyToken(iPortalUrl);
        L.supermap.SecurityManager.registerToken(iPortalUrl, token);
        //加载完DOM后，开始资源数据查询并添加
        iPortal = new L.supermap.iPortal(iPortalUrl);
        queryResouces(queryParams);
    }

    //获取用户的登陆信息
    function getLoginUserInfos() {
        var url = iPortalUrl + "/web/config/userprofile.json?token=" + token;
        $.get(url,(res)=>{
            userStateObj = res;
        })
    }

    // 查询iPortal中的资源
    function queryResouces(queryParams) {
        iPortal.queryResources(queryParams).then(function (resourcesReslut) {
            //返回的结果集，需要查看可打开下行代码
            // console.log(resourcesReslut);
            // 切换资源类型 清空之前的资源DOM
            $("#resourcesList").children().remove();
            //将结果集进行遍历，并添加到HTML中
            $.each(resourcesReslut.content, function (i) {
                var resourceItem = resourcesReslut.content[i];
                var thumbnail = resourceItem.thumbnail;
                // 此判断获取部分相对路径的default图片
                if(thumbnail.indexOf("./") === 0){
                    thumbnail = iPortalUrl + thumbnail.replace("./","/");
                }
                var resourcesDOM = $("<div class='col-xs-10 col-md-6 col-lg-4 gallery-item' id='map'>" +
                    "<div class='gallery-item-border'>" +
                    "<a class='thumbnail' style='margin-bottom: 10px'>" +
                    "<img  class='gallery-item-img' src='" + thumbnail + "' alt=''>" +
                    "</a>" +
                    "<div>" +
                    "<div class='title-checkbox-container'>"+
                        "<p class='resourcesDetails'>" + resourceItem.name + "</p>" +
                        "<input type='checkbox' class='floatLeft' id='preferenceCheck' name='checkbox' value='"+resourceItem.resourceId+"'/>" +
                    "</div>"+
                    "<div>" +
                        "<div class='operate-btn-container'>"+
                                "<a href='#' class='delete' onclick='deleteResource("+resourceItem.resourceId +")'>"+resources.text_input_value_delete+"</a>" +
                                "<a href='#' id='detail' onclick='viewResource("+resourceItem.resourceId+")'>"+resources.title_view_detail+"</a>"+
                        "</div>"+
                        "<div class='operate-btn-container'>"+
                            "<a href='#' class='edit' onclick='editResource("+resourceItem.resourceId+","+resourceItem.resourceId+")'>"+resources.title_edit_attr+"</a>"+
                            "<a href='#' class='edit' onclick='shareResource("+resourceItem.resourceId+")'>"+resources.title_share_setting+"</a>"+
                        "</div>"+
                    "</div>" +
                    "</div>")
                $("#resourcesList").append(resourcesDOM);
            });
        }).catch (()=>{
            widgets.alert.showAlert(resources.msg_query_failed, false);

        })
    };

    //获取多选CheckBox资源的id值 给（删除 和 共享资源 使用）
    function getDeleteAndShareCheckArr(){
        var checkDataEle = document.getElementsByName("checkbox");
        var check_val = [];
        for(k in checkDataEle) {
            if(checkDataEle[k].checked){
                check_val.push(checkDataEle[k].value);
            }
        }
        return check_val;
    }

    //删除资源代码块
    //点击删除前 确认弹框
    function deleteResource(ids){
        deleteIds = ids ? [ids] : getDeleteAndShareCheckArr();
        if(deleteIds.length<=0) {
            widgets.alert.showAlert(resources.msg_choise_resources_delete, false);
        }else {
            $('#deleteModel').modal('show');
        }
    }
    //发送删除请求
    function requestDeleteUrl(){
        var resourceIds = deleteIds;
        var deleteParams = {
            resourceType: resourceType,
            ids: resourceIds
        };
        new L.supermap.iPortalUser(iPortalUrl).deleteResources(deleteParams).then(result=>{
            $('#deleteModel').modal('hide');
            deleteIds = [];
            if (result.succeed) {
              widgets.alert.showAlert(resources.text_deleteSuccess, true);
              // 删除成功重新请求列表
              queryResouces(queryParams);
            } else {
              widgets.alert.showAlert(resources.msg_deleteFailure + "," + resources.msg_resourceNotExist, false);
            }
        }).catch(err => {
            widgets.alert.showAlert(resources.msg_deleteFailure, false);
        })
    }

    //编辑资源属性参数对象
    var attributes = {
        title: '',
        tags: [''],
        description: '',
        tokenRefreshUrl: '',
        refSysInfo: {
            refSysID: 0,
            projection: ''
        },
        identifier: {
            region:''
        },
        bounds: {
            west:0.0,
            east:0.0,
            south:0.0,
            north:0.0
        },
        contact: {
            personName: '',
            orgName: '',
            address: '',
            email: '',
            voiceNum: '',
            faxNum:''
        },
        dataMetaInfo: {},
        filePostfix: ''
    }
    //点击查看详情按钮
    function viewResource(ids){
        $("#edit-and-detail-plot").tabs('select',0);
        var item = new L.supermap.iPortalResource(iPortalUrl,{resourceId:ids,resourceType:resourceType});
        item.load().then((result)=>{
            // 资源不存在或无权限提示
            if (result && !result.succeed) {
              widgets.alert.showAlert(resources.msg_resourceNotExist, false);
              return;
            }
            //创建详情面板
            new L.supermap.plotting.initIportalStylePanel("iPortalDetailPanel",resourceType,item.sourceJSON,'detail');
        });
    }
    //点击编辑属性按钮
    function editResource(ids){
        viewResource(ids)
        $("#edit-and-detail-plot").tabs('select',1);
        var item = new L.supermap.iPortalResource(iPortalUrl,{resourceId:ids,resourceType:resourceType});
        item.load().then((result)=>{
            // 资源不存在或无权限提示
            if (result && !result.succeed) {
              widgets.alert.showAlert(resources.msg_resourceNotExist, false);
              return;
            }
            //创建属性面板 
            new L.supermap.plotting.initIportalStylePanel("plotPanel", resourceType, item.sourceJSON,'edit');
            itemData = item.sourceJSON;
            //填充attributes对象
            switch (resourceType) {
                case 'MAP':
                    attributes.title = itemData.title!=null?itemData.title:'';
                    break;
                case 'SERVICE':
                    attributes.title = itemData.resTitle!=null?itemData.resTitle:'';
                    attributes.tokenRefreshUrl = itemData.tokenRefreshUrl!=null?itemData.tokenRefreshUrl:'';
                    attributes.refSysInfo.refSysID = itemData.metadata.refSysInfo!=null?itemData.metadata.refSysInfo.refSysID:'';
                    attributes.refSysInfo.projection = itemData.metadata.refSysInfo!=null?itemData.metadata.refSysInfo.mdCoRefSys.projection:'';
                    attributes.identifier.region = itemData.metadata.dataIdInfo!=null?itemData.metadata.dataIdInfo.dataIdent.dataExt.exDesc:'';
                    attributes.bounds.west = itemData.metadata.dataIdInfo!=null?itemData.metadata.dataIdInfo.dataIdent.dataExt.geoEle.geoBndBox.westBL:'';
                    attributes.bounds.east = itemData.metadata.dataIdInfo!=null?itemData.metadata.dataIdInfo.dataIdent.dataExt.geoEle.geoBndBox.eastBL:'';
                    attributes.bounds.south = itemData.metadata.dataIdInfo!=null?itemData.metadata.dataIdInfo.dataIdent.dataExt.geoEle.geoBndBox.southBL:'';
                    attributes.bounds.north = itemData.metadata.dataIdInfo!=null?itemData.metadata.dataIdInfo.dataIdent.dataExt.geoEle.geoBndBox.northBL:'';
                    attributes.contact.personName = itemData.metadata.mdContact!=null?itemData.metadata.mdContact.rpIndName:'';
                    attributes.contact.orgName = itemData.metadata.mdContact!=null?itemData.metadata.mdContact.rpOrgName:'';
                    attributes.contact.address = itemData.metadata.mdContact!=null?itemData.metadata.mdContact.rpCntInfo.cntAddress.delPoint:'';
                    attributes.contact.email = itemData.metadata.mdContact!=null?itemData.metadata.mdContact.rpCntInfo.cntAddress.EMailAdd:'';
                    attributes.contact.voiceNum = itemData.metadata.mdContact!=null?itemData.metadata.mdContact.rpCntInfo.voiceNum:'';
                    attributes.contact.faxNum = itemData.metadata.mdContact!=null?itemData.metadata.mdContact.rpCntInfo.faxNum:'';
                    break;
                case 'SCENE':
                    attributes.title = itemData.name!=null?itemData.name:'';
                    break
                case 'DATA':
                    attributes.title = itemData.fileName!=null?itemData.fileName.substring(0,itemData.fileName.lastIndexOf(".")):'';
                    attributes.filePostfix = itemData.fileName!=null?itemData.fileName.substr(itemData.fileName.lastIndexOf(".")):'';
                    attributes.dataMetaInfo = itemData.dataMetaInfo!=null?itemData.dataMetaInfo:{};
                    break;
                case 'INSIGHTS_WORKSPACE':
                    attributes.title = itemData.name!=null?itemData.name:'';
                    break;
                case 'MAP_DASHBOARD':
                    attributes.title = itemData.name!=null?itemData.name:'';
                    break;
            }
            attributes.tags = itemData.tags!=null?itemData.tags.join(" "):[];
            attributes.description = itemData.description!=null?itemData.description:'';
        });
    }
    //修改表格属性值后 则会立刻调用此函数 {rowIndex:改变属性的数据索引 rowData:改变属性后的数据对象 changes:改变的属性值}
    function afterModifySelectFeature(rowIndex, rowData, changes){
        if(rowData.length !== 0 ){
            new Promise(() => {
                if(rowData.length !== 0) {
                    updateSelectFeature(rowData,itemData);
                }
                return;
            })
        }
    }
    //调用资源update接口，模拟服务metadata对象（所有字段） 提交后端 防止因为后端返回metadata对象为空 造成属性提交报错的问题（如果有变化 就替换 否则提交默认值）
    var entity = {
        metadata: {
            dataIdInfo: {
                dataIdent: {
                    idCitation: {
                        resTitle: ""
                    },
                    idAbs: "",
                    dataExt: {
                        exDesc: "",
                        geoEle: {
                            geoBndBox: {
                                westBL: "",
                                eastBL: "",
                                southBL: "",
                                northBL: "",
                            },
                        },
                    },
                },
            },
            refSysInfo: {
                refSysID: "",
                mdCoRefSys: {
                    projection: ""
                }
            },
            mdContact: {
                rpIndName: "",
                rpOrgName: "",
                rpCntInfo: {
                    cntAddress: {
                        delPoint: "",
                        EMailAdd: ""
                    },
                    voiceNum: "",
                    faxNum: ""
                }
            }
        },
    }
    //构造属性对象 提交参数 更改属性值
    function updateSelectFeature(updated,data) {
        switch (updated.key){
            case "title":
                if(attributes.title === updated.value) {
                    return;
                }
                attributes.title = updated.value;
                break;
            case "tags":
                if(attributes.tags === updated.value) {
                    return;
                }
                attributes.tags = updated.value.split(",");
                break;
            case "description":
                if(attributes.description === updated.value) {
                    return;
                }
                attributes.description = updated.value;
                break;
            case "tokenRefreshUrl":
                if(attributes.tokenRefreshUrl === updated.value) {
                    return;
                }
                attributes.tokenRefreshUrl = updated.value;
                break;
            case "refSysID":
                if(attributes.refSysInfo.refSysID === updated.value) {
                    return;
                }
                attributes.refSysInfo.refSysID = updated.value;
                break;
            case "projection":
                if(attributes.refSysInfo.projection === updated.value) {
                    return;
                }
                attributes.refSysInfo.projection = updated.value;
                break;
            case "region":
                if(attributes.identifier.region === updated.value) {
                    return;
                }
                attributes.identifier.region = updated.value;
                break;
            case "west":
                if(attributes.bounds.west === updated.value) {
                    return;
                }
                attributes.bounds.west = updated.value;
                break;
            case "east":
                if(attributes.bounds.east === updated.value) {
                    return;
                }
                attributes.bounds.east = updated.value;
                break;
            case "south":
                if(attributes.bounds.south === updated.value) {
                    return;
                }
                attributes.bounds.south = updated.value;
                break;
            case "north":
                if(attributes.bounds.north === updated.value) {
                    return;
                }
                attributes.bounds.north = updated.value;
                break;
            case "personName":
                if(attributes.contact.personName === updated.value) {
                    return;
                }
                attributes.contact.personName = updated.value;
                break;
            case "orgName":
                if(attributes.contact.orgName === updated.value) {
                    return;
                }
                attributes.contact.orgName = updated.value;
                break;
            case "address":
                if(attributes.contact.address === updated.value) {
                    return;
                }
                attributes.contact.address = updated.value;
                break;
            case "email":
                if(attributes.contact.email === updated.value) {
                    return;
                }
                attributes.contact.email = updated.value;
                break;
            case "voiceNum":
                if(attributes.contact.voiceNum === updated.value) {
                    return;
                }
                attributes.contact.voiceNum = updated.value;
                break;
            case "faxNum":
                if(attributes.contact.faxNum === updated.value) {
                    return;
                }
                attributes.contact.faxNum = updated.value;
                break;
            
            case "bounds":
                if(attributes.dataMetaInfo) {
                    var bounds = attributes.dataMetaInfo.bounds!=null?attributes.dataMetaInfo.bounds:'';
                    if(bounds === updated.value) {
                        return;
                    }
                }
                attributes.dataMetaInfo.bounds = updated.value;
                break;
            case "epsgCode":
                if(attributes.dataMetaInfo) {
                    var epsgCode = attributes.dataMetaInfo.epsgCode!=null?attributes.dataMetaInfo.epsgCode:'';
                    if(epsgCode === updated.value) {
                        return;
                    }
                }
                attributes.dataMetaInfo.epsgCode = updated.value;
                break;
            case "previewURL":
                if(attributes.dataMetaInfo) {
                    var previewURL = attributes.dataMetaInfo.previewURL!=null?attributes.dataMetaInfo.previewURL:'';
                    if( previewURL=== updated.value) {
                        return;
                    }
                }
                attributes.dataMetaInfo.previewURL = updated.value;
                break;
            case "providers":
                if(attributes.dataMetaInfo) {
                    var providers = attributes.dataMetaInfo.providers!=null?attributes.dataMetaInfo.providers:'';
                    if(providers === updated.value) {
                        return;
                    }
                }
                attributes.dataMetaInfo.providers = updated.value;
                break;
        }
        var item = new L.supermap.iPortalResource(iPortalUrl,{resourceId:data.id,resourceType:resourceType});
        item.load().then(()=>{
            switch (resourceType) {
                case 'MAP':
                    item.sourceJSON.title = attributes.title;
                    break;
                case 'SERVICE':
                    entity.metadata.dataIdInfo.dataIdent.idCitation.resTitle = attributes.title;
                    item.sourceJSON.tokenRefreshUrl = attributes.tokenRefreshUrl;
                    entity.metadata.refSysInfo.refSysID = attributes.refSysInfo.refSysID;
                    entity.metadata.refSysInfo.mdCoRefSys.projection = attributes.refSysInfo.projection;
                    entity.metadata.dataIdInfo.dataIdent.dataExt.exDesc = attributes.identifier.region;
                    entity.metadata.dataIdInfo.dataIdent.dataExt.geoEle.geoBndBox.westBL = attributes.bounds.west;
                    entity.metadata.dataIdInfo.dataIdent.dataExt.geoEle.geoBndBox.eastBL = attributes.bounds.east;
                    entity.metadata.dataIdInfo.dataIdent.dataExt.geoEle.geoBndBox.southBL = attributes.bounds.south;
                    entity.metadata.dataIdInfo.dataIdent.dataExt.geoEle.geoBndBox.northBL = attributes.bounds.north;
                    entity.metadata.mdContact.rpIndName = attributes.contact.personName;
                    entity.metadata.mdContact.rpOrgName = attributes.contact.orgName;
                    entity.metadata.mdContact.rpCntInfo.cntAddress.delPoint = attributes.contact.address;
                    entity.metadata.mdContact.rpCntInfo.cntAddress.EMailAdd = attributes.contact.email;
                    entity.metadata.mdContact.rpCntInfo.voiceNum = attributes.contact.voiceNum;
                    entity.metadata.mdContact.rpCntInfo.faxNum = attributes.contact.faxNum;
                    item.sourceJSON.metadata =  entity.metadata;
                    break;
                case "DATA":
                    item.sourceJSON.fileName = attributes.title + attributes.filePostfix;
                    item.sourceJSON.dataMetaInfo = attributes.dataMetaInfo;
                    break
                case "SCENE":
                    item.sourceJSON.name = attributes.title;
                    break;
                case "INSIGHTS_WORKSPACE":
                    item.sourceJSON.name = attributes.title;
                    break;
                case "MAP_DASHBOARD":
                    item.sourceJSON.name = attributes.title;
                    break;
            }
            item.sourceJSON.tags = attributes.tags;
            item.sourceJSON.description = attributes.description;
            item.update().then(res => {
                if(res.succeed) {
                    widgets.alert.showAlert(resources.msg_updateSuccess, true);
                }else {
                    widgets.alert.showAlert(resources.msg_updateFailure+","+res.error.errorMsg, false);
                }
            }).catch(()=>{
            });
        })
    }
    
    //共享设置代码块
    //搜索添加用户
    function searchUser(){
        var userName = $("#add-user-val").val();
        var nicknameInfosUrl = iPortalUrl+"/web/users/nicknameinfos.json?name="+userName + "&token=" + token;
        $.get(nicknameInfosUrl,(res)=>{
            if(res.length === 0){
                widgets.alert.showAlert(resources.msg_user_not_exist,false);
            }
            for(var item of res){
                if(item.roles.includes("ADMIN")){
                    widgets.alert.showAlert(resources.msg_not_share_admin,false);
                    break;
                }else if(!checkUser(true, item.name)){
                    break;
                }
                putUserToSettingEntities(item.name,item.nickname,null);
            }
        })
    }
    // 检查选择的用户是否符合分享条件
    function checkUser(enableTips,username){
        //验证分享的用户列表中是否已存在该用户
        for(var user of usersSettingEntities){
            if(user.entityName === username || user.aliasName === username){
                if(enableTips) {
                    widgets.alert.showAlert(resources.msg_user_added,false);
                }
                return false;
            }
        }
        return true;
    }
    // 构造用户实体参数对象
    function putUserToSettingEntities(name,nickname,id){
        var authorizeList = getAuthorizeList("SEARCH");//添加的用户默认具有搜索权限
        var entity = {
            "permissionType": null,
            "aliasName": nickname,
            "entityRoles": [],
            "entityType": "USER",
            "entityName": name,
            "entityId": id,
            "authorizeList": authorizeList
        };
        usersSettingEntities.push(entity);
        showUserShare();
    }
    // 根据查询的用户记录，渲染页面，进行共享设置
    function showUserShare() {
        $("#user_tbody").empty();
        var cloneUsersList = Object.assign([],usersSettingEntities);
        for (var i = 0; i < cloneUsersList.length; i++) {
            switch (resourceType) {
                case 'MAP':
                case 'SCENE':
                case 'INSIGHTS_WORKSPACE':
                    var shareMapDOM = $("<tr>" +
                        "<td>" + cloneUsersList[i].entityName + "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='search-user"+i+"'" +
                                "onclick='clickSearchCheckBox("+JSON.stringify(cloneUsersList[i])+","+JSON.stringify("user")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='view-user"+i+"'" +
                                "onclick='clickViewCheckBox("+JSON.stringify(cloneUsersList[i])+","+JSON.stringify("user")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='edit-user"+i+"'" +
                                "onclick='clickEditCheckBox("+JSON.stringify(cloneUsersList[i])+","+JSON.stringify("user")+")'"+
                            "/>" +
                        "</td>" +
                        "<td onclick='removeUsersSettingEntity("+i+")'>"+resources.text_input_value_delete+"</td>" +
                    "</tr>")
                    $("#user_tbody").append(shareMapDOM);
                    break;
                case 'SERVICE':
                case 'MAP_DASHBOARD':
                    var shareMapDOM = $("<tr>" +
                        "<td>" + cloneUsersList[i].entityName + "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='search-user"+i+"'" +
                                "onclick='clickSearchCheckBox("+JSON.stringify(cloneUsersList[i])+","+JSON.stringify("user")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='view-user"+i+"'" +
                                "onclick='clickViewCheckBox("+JSON.stringify(cloneUsersList[i])+","+JSON.stringify("user")+")'"+
                            "/>" +
                        "</td>" +
                        "<td onclick='removeUsersSettingEntity("+i+")'>"+resources.text_input_value_delete+"</td>" +
                    "</tr>")
                    $("#user_tbody").append(shareMapDOM);
                    break;
                case 'DATA':
                    var shareMapDOM = $("<tr>" +
                        "<td>" + cloneUsersList[i].entityName + "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='search-user"+i+"'" +
                                "onclick='clickSearchCheckBox("+JSON.stringify(cloneUsersList[i])+","+JSON.stringify("user")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='download-user"+i+"'" +
                                "onclick='clickDownloadCheckBox("+JSON.stringify(cloneUsersList[i])+","+JSON.stringify("user")+")'"+
                            "/>" +
                        "</td>" +
                        "<td onclick='removeUsersSettingEntity("+i+")'>"+resources.text_input_value_delete+"</td>" +
                    "</tr>")
                    $("#user_tbody").append(shareMapDOM);
                    break;
            }
            cloneUsersList[i].authorizeList.forEach((authorizeListItem,index)=>{
                $("input[value='"+authorizeListItem+"-user"+i+"']").prop("checked", true);
            })
        }
    }
    //删除用户的共享权限设置
    function removeUsersSettingEntity(index) {
        var obj = this.usersSettingEntities[index];
        this.usersSettingEntities.splice(index,1);
        this.showUserShare();
    }

    // 根据查询的部门记录，渲染页面，进行共享设置
    function showDepartmentShare() {
        $("#department_tbody").empty();
        var cloneDepartmentList = Object.assign([],departmentSettingEntities);
        for (var i = 0; i < cloneDepartmentList.length; i++) {
            switch (resourceType) {
                case 'MAP':
                case 'SCENE':
                case 'INSIGHTS_WORKSPACE':
                    var shareMapDOM = $("<tr>" +
                        "<td>" + cloneDepartmentList[i].entityName + "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='search-department"+i+"'" +
                                "onclick='clickSearchCheckBox("+JSON.stringify(cloneDepartmentList[i])+","+JSON.stringify("department")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='view-department"+i+"'" +
                                "onclick='clickViewCheckBox("+JSON.stringify(cloneDepartmentList[i])+","+JSON.stringify("department")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='edit-department"+i+"'" +
                                "onclick='clickEditCheckBox("+JSON.stringify(cloneDepartmentList[i])+","+JSON.stringify("department")+")'"+
                            "/>" +
                        "</td>" +
                        "<td onclick='removeDepartmentSettingEntity("+i+")'>"+resources.text_input_value_delete+"</td>" +
                    "</tr>")
                    $("#department_tbody").append(shareMapDOM);
                    break;
                case 'SERVICE':
                case 'MAP_DASHBOARD':
                    var shareMapDOM = $("<tr>" +
                        "<td>" + cloneDepartmentList[i].entityName + "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='search-department"+i+"'" +
                                "onclick='clickSearchCheckBox("+JSON.stringify(cloneDepartmentList[i])+","+JSON.stringify("department")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='view-department"+i+"'" +
                                "onclick='clickViewCheckBox("+JSON.stringify(cloneDepartmentList[i])+","+JSON.stringify("department")+")'"+
                            "/>" +
                        "</td>" +
                        "<td onclick='removeDepartmentSettingEntity("+i+")'>"+resources.text_input_value_delete+"</td>" +
                    "</tr>")
                    $("#department_tbody").append(shareMapDOM);
                    break;
                case 'DATA':
                    var shareMapDOM = $("<tr>" +
                        "<td>" + cloneDepartmentList[i].entityName + "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='search-department"+i+"'" +
                                "onclick='clickSearchCheckBox("+JSON.stringify(cloneDepartmentList[i])+","+JSON.stringify("department")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='download-department"+i+"'" +
                                "onclick='clickDownloadCheckBox("+JSON.stringify(cloneDepartmentList[i])+","+JSON.stringify("department")+")'"+
                            "/>" +
                        "</td>" +
                        "<td onclick='removeDepartmentSettingEntity("+i+")'>"+resources.text_input_value_delete+"</td>" +
                    "</tr>")
                    $("#department_tbody").append(shareMapDOM);
                    break;
            }
            cloneDepartmentList[i].authorizeList.forEach((authorizeListItem,index)=>{
                $("input[value='"+authorizeListItem+"-department"+i+"']").prop("checked", true);
            })
        }
    }
    // 检查输入的部门是否存在
    function checkDepartmentIsExist(name,departments) {
        var department = null;
        for(var dep of departments){
            if(dep.name === name){
                department = dep;
                break;
            }else {
                if(dep.childs){
                    department = this.checkDepartmentIsExist(name,dep.childs);
                    if(department){
                        break;
                    }
                }
            }
        }
        return department;
    }


    // 获取群组列表数据函数
    function getGroupList() {
        var groupUrl = iPortalUrl + "/web/groups/sharegroups.json?token=" + token;
        $.get(groupUrl,(res)=>{
            if(res.length>0) {
                groupList = res;
                return;
            }
        })
    }
    // 根据群组列表数据，渲染页面，进行共享设置
    function showGroupShare() {
        $("#group_tbody").empty();
        var cloneGroupsList = Object.assign([],groupsSettingEntities);
        for (var i = 0; i < cloneGroupsList.length; i++) {
            switch (resourceType) {
                case 'MAP':
                case 'SCENE':
                case 'INSIGHTS_WORKSPACE':
                    var shareMapDOM = $("<tr>" +
                        "<td>" + cloneGroupsList[i].entityName + "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='search-group"+i+"'" +
                                "onclick='clickSearchCheckBox("+JSON.stringify(cloneGroupsList[i])+","+JSON.stringify("group")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='view-group"+i+"'" +
                                "onclick='clickViewCheckBox("+JSON.stringify(cloneGroupsList[i])+","+JSON.stringify("group")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='edit-group"+i+"'" +
                                "onclick='clickEditCheckBox("+JSON.stringify(cloneGroupsList[i])+","+JSON.stringify("group")+")'"+
                            "/>" +
                        "</td>" +
                    "</tr>")
                    $("#group_tbody").append(shareMapDOM);
                    break;
                case 'SERVICE':
                case 'MAP_DASHBOARD':
                    var shareMapDOM = $("<tr>" +
                        "<td>" + cloneGroupsList[i].entityName + "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='search-group"+i+"'" +
                                "onclick='clickSearchCheckBox("+JSON.stringify(cloneGroupsList[i])+","+JSON.stringify("group")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='view-group"+i+"'" +
                                "onclick='clickViewCheckBox("+JSON.stringify(cloneGroupsList[i])+","+JSON.stringify("group")+")'"+
                            "/>" +
                        "</td>" +
                    "</tr>")
                    $("#group_tbody").append(shareMapDOM);
                    break;
                case 'DATA':
                    var shareMapDOM = $("<tr>" +
                        "<td>" + cloneGroupsList[i].entityName + "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='search-group"+i+"'" +
                                "onclick='clickSearchCheckBox("+JSON.stringify(cloneGroupsList[i])+","+JSON.stringify("group")+")'"+
                            "/>" +
                        "</td>" +
                        "<td>" +
                            "<input type='checkbox'" +
                                "value='download-group"+i+"'" +
                                "onclick='clickDownloadCheckBox("+JSON.stringify(cloneGroupsList[i])+","+JSON.stringify("group")+")'"+
                            "/>" +
                        "</td>" +
                    "</tr>")
                    $("#group_tbody").append(shareMapDOM);
                    break;
            }
            cloneGroupsList[i].authorizeList.forEach((authorizeListItem,index)=>{
                $("input[value='"+authorizeListItem+"-group"+i+"']").prop("checked", true);
            })
        }
    }
    //删除部门的共享权限设置
    function removeDepartmentSettingEntity(index){
        let obj = this.departmentSettingEntities[index];
        this.departmentSettingEntities.splice(index,1);
        this.showDepartmentShare();
    }

    //点击共享设置前，确认弹框（初始化弹框内容）
    function shareResource(ids){
        // 获取群组列表数据
        getGroupList();
        // 获取登录用户信息数据
        getLoginUserInfos();
        groupsSettingEntities = [];
        for(let group of groupList){
            let settingEntity = {
                "permissionType": "",
                "aliasName": null,
                "entityRoles": [],
                "entityType": "IPORTALGROUP",
                "entityName": group.groupName,
                "entityId": group.id,
                "authorizeList": []
            };
            groupsSettingEntities.push(settingEntity);
        }
        $('#shareModal').modal('show');
        shareIds = ids ? [ids] : getDeleteAndShareCheckArr();
        if(shareIds.length<=0) {
            widgets.alert.showAlert(resources.msg_choise_resources_share, false);
            return;
        }
        $("#public").empty();
        $("#user_thead").empty();
        $("#user_tbody").empty();
        $("#group_thead").empty();
        $("#group_tbody").empty();
        $("#department_thead").empty();
        $("#department_tbody").empty();
        $("#add-user-val").val("");
        $("#add-department-val").val("");
        //公开
        switch (resourceType) {
            case 'MAP':
            case 'SCENE':
            case 'INSIGHTS_WORKSPACE':
                sharePublicDOM = $("<div class='col-md-4 col-xl-4 gallery-item' id='shareCheckboxs'>" +
                    "<div class='publicPane sub-font' id='search'>" +
                        "<input type='checkbox'" +
                            "value='search'" +
                            "onchange='clickSearchCheckBox("+JSON.stringify(publicSettingEntity).replace(/\“/g,"'")+","+JSON.stringify("public")+")'"+
                        "/>" +
                        "&nbsp; <span>"+resources.text_user_search+"</span>" +
                    "</div>" +
                    "<div class='publicPane sub-font' id='view'>" +
                        "<input type='checkbox'" +
                            "value='view'" +
                            "onchange='clickViewCheckBox("+JSON.stringify(publicSettingEntity).replace(/\“/g,"'")+","+JSON.stringify("public")+")'"+
                        "/>" +
                        "&nbsp; <span>"+resources.text_user_view+"</span>" +
                    "</div>" +
                    "<div class='publicPane sub-font' id='edit'>" +
                        "<input type='checkbox'" +
                            "value='edit'" +
                            "onchange='clickEditCheckBox("+JSON.stringify(publicSettingEntity).replace(/\“/g,"'")+","+JSON.stringify("public")+")'"+
                        "/>" +
                        "&nbsp; <span>"+resources.text_user_editor+"</span>" +
                    "</div>" +
                "</div>")
                break;
            case 'SERVICE':
            case 'MAP_DASHBOARD':
                sharePublicDOM = $("<div class='col-md-4 col-xl-4 gallery-item' id='shareCheckboxs'>" +
                    "<div class='publicPane sub-font' id='search'>" +
                        "<input type='checkbox'" +
                            "value='search'" +
                            "onchange='clickSearchCheckBox("+JSON.stringify(publicSettingEntity).replace(/\“/g,"'")+","+JSON.stringify("public")+")'"+
                        "/>" +
                        "&nbsp; <span>"+resources.text_user_search+"</span>" +
                    "</div>" +
                    "<div class='publicPane sub-font' id='view'>" +
                        "<input type='checkbox'" +
                            "value='view'" +
                            "onchange='clickViewCheckBox("+JSON.stringify(publicSettingEntity).replace(/\“/g,"'")+","+JSON.stringify("public")+")'"+
                        "/>" +
                        "&nbsp; <span>"+resources.text_user_view+"</span>" +
                    "</div>" +
                "</div>")
                break;
            case 'DATA':
                sharePublicDOM = $("<div class='col-md-4 col-xl-4 gallery-item' id='shareCheckboxs'>" +
                    "<div class='publicPane sub-font' id='search'>" +
                        "<input type='checkbox'" +
                            "value='search'" +
                            "onchange='clickSearchCheckBox("+JSON.stringify(publicSettingEntity).replace(/\“/g,"'")+","+JSON.stringify("public")+")'"+
                        "/>" +
                        "&nbsp; <span>"+resources.text_user_search+"</span>" +
                    "</div>" +
                    "<div class='publicPane sub-font' id='download'>" +
                        "<input type='checkbox'" +
                            "value='download'" +
                            "onchange='clickDownloadCheckBox("+JSON.stringify(publicSettingEntity).replace(/\“/g,"'")+","+JSON.stringify("public")+")'"+
                        "/>" +
                        "&nbsp; <span>"+resources.text_user_download+"</span>" +
                    "</div>" +
                "</div>")
                break;
        }
        initDepartmentUserGroupThead("user",resources.text_nickname);
        initDepartmentUserGroupThead("department",resources.text_department);
        initDepartmentUserGroupThead("group",resources.text_group);

        $("#public").append(sharePublicDOM)
        var item = new L.supermap.iPortalResource(iPortalUrl,{resourceId:shareIds[0],resourceType:resourceType});
        item.load().then(()=>{
            if(item.sourceJSON.authorizeSetting && item.sourceJSON.authorizeSetting.length > 0){
                for(let entity of item.sourceJSON.authorizeSetting){
                    let permissionType = entity.permissionType || entity.dataPermissionType;
                    switch(entity.entityType) {
                        case "USER":
                            if(entity.entityName === "GUEST") {
                                //为其增加一权限属性，用于处理复选框数据双向绑定
                                var entityObj = Object.assign({},entity);
                                entityObj["authorizeList"] = getAuthorizeList(permissionType);
                                publicSettingEntity = entityObj;
                            }else {
                                if(!entity.entityName || userStateObj.userName === entity.entityName){
                                    break;
                                }
                                var entityObj = Object.assign({},entity);
                                entityObj["authorizeList"] = getAuthorizeList(permissionType);
                                usersSettingEntities.push(entityObj);
                            }
                            break;
                        case "IPORTALGROUP":
                            var cloneGroupsEntities = Object.assign([],groupsSettingEntities)
                            for(var groupItem of cloneGroupsEntities){
                                if(groupItem.entityId === entity.entityId){
                                    groupItem.authorizeList = getAuthorizeList(permissionType);
                                    groupItem.permissionType = entity.permissionType;
                                    break;
                                }
                            }
                            groupsSettingEntities = cloneGroupsEntities;
                            break;
                        case "DEPARTMENT":
                            var entityObj = Object.assign({},entity);
                            entityObj["authorizeList"] = getAuthorizeList(permissionType);
                            departmentSettingEntities.push(entityObj);
                            break;
                    }
                }
            }
            publicSettingEntity.authorizeList.forEach((authorizeListItem,index)=>{
                $("input[value='"+authorizeListItem+"']").prop("checked", true);
            })
            if(departmentSettingEntities.length>0) {
                showDepartmentShare();
            }
            if(usersSettingEntities.length>0) {
                showUserShare();
            }
            if(groupsSettingEntities.length>0) {
                showGroupShare();
            }
        })
    }
    //初始化部门用户群组的表格头部内容
    function initDepartmentUserGroupThead(renderDOMType,name){
        var tr = document.createElement("tr");
        //添加昵称（用户名）
        var td_Name = document.createElement("th");
        var text_Name = document.createTextNode(name);
        td_Name.append(text_Name);
        tr.append(td_Name);
        $("#"+renderDOMType+"_thead").append(tr);
        //添加可检索
        var td_Name = document.createElement("th");
        var text_Name = document.createTextNode(resources.text_is_search);
        td_Name.append(text_Name);
        tr.append(td_Name);
        $("#"+renderDOMType+"_thead").append(tr);

        switch (resourceType) {
            case 'MAP':
            case 'SCENE':
            case 'INSIGHTS_WORKSPACE':
                //可查看
                var td_Value = document.createElement("th");
                var text_Value = document.createTextNode(resources.text_is_view);
                td_Value.append(text_Value);
                tr.append(td_Value);
                $("#"+renderDOMType+"_thead").append(tr);

                //可编辑
                var td_Value = document.createElement("th");
                var text_Value = document.createTextNode(resources.text_is_edit);
                td_Value.append(text_Value);
                tr.append(td_Value);
                $("#"+renderDOMType+"_thead").append(tr);

                break;
            case 'SERVICE':
            case 'MAP_DASHBOARD':
                //可查看
                var td_Value = document.createElement("th");
                var text_Value = document.createTextNode(resources.text_is_view);
                td_Value.append(text_Value);
                tr.append(td_Value);
                $("#"+renderDOMType+"_thead").append(tr);

                break;
            case 'DATA':
                //可下载
                var td_Value = document.createElement("th");
                var text_Value = document.createTextNode(resources.text_is_download);
                td_Value.append(text_Value);
                tr.append(td_Value);
                $("#"+renderDOMType+"_thead").append(tr);

                break;
        }
        if(renderDOMType === 'group') {
            return;
        }
        var td_Value = document.createElement("th");
        var text_Value = document.createTextNode(resources.btn_operate);
        td_Value.append(text_Value);
        tr.append(td_Value);
        $("#"+renderDOMType+"_thead").append(tr);
    }
    //发送共享设置请求
    function requestShareUrl(){
        var resourceIds = shareIds;
        var entities = getShareEntities();
        queryShareParams = new L.supermap.iPortalShareParam({
            ids:resourceIds,
            entities:entities,
            resourceType:resourceType
        });
        iPortal.updateResourcesShareSetting(queryShareParams).then(result=>{
            $('#shareModal').modal('hide');
            usersSettingEntities = [];
            departmentSettingEntities = [];
            groupsSettingEntities = [];
            if (result.succeed) {
              widgets.alert.showAlert(resources.msg_shareSuccess, true);
            } else {
              widgets.alert.showAlert(resources.msg_shareFailed + "," + resources.msg_resourceNotExist, false);
            }
        }).catch(err => {
            widgets.alert.showAlert(resources.msg_shareFailed, false);
        })
    }
    
    //关闭弹框后 清空实体参数对象 防止重复渲染
    function removeUser(){
        usersSettingEntities = [];
        departmentSettingEntities = [];
        groupsSettingEntities = [];
    }

    //获取共享的实体参数
    function getShareEntities(){
        shareSettingList = [];
        //公开
        addSettingEntity(publicSettingEntity);
        //用户
        for(var user of usersSettingEntities){
            addSettingEntity(user);
        }
        //部门
        for(var department of departmentSettingEntities){
            addSettingEntity(department);
        }
        //群组
        for(var group of groupsSettingEntities){
            addSettingEntity(group);
        }
        return shareSettingList;
    }
    //生成分享的entities参数
    function addSettingEntity(obj){
        var settingEntity =  dealShareSettingParam(obj);
        if(settingEntity){
            shareSettingList.push(settingEntity);
        }
    }
    //处理共享设置的参数
    function dealShareSettingParam(obj) {
        var authorize = "";
        if(!obj.authorizeList){
            return null;
        }
        if(obj.authorizeList.includes("edit")){
            authorize = obj.entityName === userStateObj.userName ? "DELETE" : "READWRITE";
        }else if(obj.authorizeList.includes("view")){
            authorize =  "READ";
        }else if(obj.authorizeList.includes("download")){
            authorize =  "DOWNLOAD";
        }else if(obj.authorizeList.includes("search")){
            authorize = "SEARCH";
        }
        if(authorize){
            if(resourceType === "DATA") {
                obj.dataPermissionType = authorize;
            }
            obj.permissionType = authorize;
            let targetPermissionEntity  = Object.assign({},obj);
            delete targetPermissionEntity.authorizeList;
            delete targetPermissionEntity.aliasName;
            delete targetPermissionEntity.entityRoles;
            return targetPermissionEntity;
        }else {
            return null;
        }
    }
    //根据已有的权限生成authorizeList，用于复选框双向绑定
    function getAuthorizeList(permissionType){
        let authorizeList = [];
        switch(permissionType){
            case "SEARCH":
                authorizeList = ["search"];
                break;
            case "READ":
                authorizeList = ["search","view"];
                break;
            case "DOWNLOAD":
                authorizeList = ["search","download"];
                break;
            case "READWRITE":
                authorizeList = ["search","view","edit"];
                break;
            case "DELETE":
                authorizeList = ["search","view","edit"];
                break;
            default:
                break;
        }
        return authorizeList;
    }
    
    //点击可检索逻辑
    function clickSearchCheckBox(obj,type){
        if(!obj.authorizeList || (obj.authorizeList).indexOf("search") === -1){
            obj.authorizeList = ["search"];
        }else {
            obj.authorizeList = [];
        }
        if(type === 'public') {
            publicSettingEntity = obj;
            if($("input[value='search']").is(':checked')){
                obj.authorizeList.forEach(authorizeListItem=>{
                    $("input[value='"+authorizeListItem+"']").prop("checked", true);
                    $("input[value='view']").prop("checked", false);
                    $("input[value='edit']").prop("checked", false);
                    $("input[value='download']").prop("checked", false);
                })
            }else {
                $("input[value='search']").prop("checked", false);
                $("input[value='view']").prop("checked", false);
                $("input[value='edit']").prop("checked", false);
                $("input[value='download']").prop("checked", false);
            }
        }else if(type === 'user') {
            usersSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    usersSettingEntities[index] = obj;
                }
                if($("input[value='search-user"+index+"']").is(':checked')){
                    obj.authorizeList.forEach(authorizeListItem=>{
                        $("input[value='"+authorizeListItem+"-user"+index+"']").prop("checked", true);
                        $("input[value='view-user"+index+"']").prop("checked", false);
                        $("input[value='edit-user"+index+"']").prop("checked", false);
                        $("input[value='download-user"+index+"']").prop("checked", false);
                    })
                }else {
                    $("input[value='search-user"+index+"']").prop("checked", false);
                    $("input[value='view-user"+index+"']").prop("checked", false);
                    $("input[value='edit-user"+index+"']").prop("checked", false);
                    $("input[value='download-user"+index+"']").prop("checked", false);
                }
            })
        }else if(type === 'department') {
            departmentSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    departmentSettingEntities[index] = obj;
                }
                if($("input[value='search-department"+index+"']").is(':checked')){
                    obj.authorizeList.forEach(authorizeListItem=>{
                        $("input[value='"+authorizeListItem+"-department"+index+"']").prop("checked", true);
                        $("input[value='view-department"+index+"']").prop("checked", false);
                        $("input[value='edit-department"+index+"']").prop("checked", false);
                        $("input[value='download-department"+index+"']").prop("checked", false);
                    })
                }else {
                    $("input[value='search-department"+index+"']").prop("checked", false);
                    $("input[value='view-department"+index+"']").prop("checked", false);
                    $("input[value='edit-department"+index+"']").prop("checked", false);
                    $("input[value='download-department"+index+"']").prop("checked", false);
                }
            })
        }else if(type === 'group') {
            groupsSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    groupsSettingEntities[index] = obj;
                }
                if($("input[value='search-group"+index+"']").is(':checked')){
                    obj.authorizeList.forEach(authorizeListItem=>{
                        $("input[value='"+authorizeListItem+"-group"+index+"']").prop("checked", true);
                        $("input[value='view-group"+index+"']").prop("checked", false);
                        $("input[value='edit-group"+index+"']").prop("checked", false);
                        $("input[value='download-group"+index+"']").prop("checked", false);
                    })
                }else {
                    $("input[value='search-group"+index+"']").prop("checked", false);
                    $("input[value='view-group"+index+"']").prop("checked", false);
                    $("input[value='edit-group"+index+"']").prop("checked", false);
                    $("input[value='download-group"+index+"']").prop("checked", false);
                }
            })
        }
    }
    //点击可下载逻辑
    function clickDownloadCheckBox(obj,type){
        if(!obj.authorizeList || (obj.authorizeList).indexOf("download") === -1){
            obj.authorizeList = ["search","download"];
        }else if((obj.authorizeList).indexOf("search") !== -1){
            obj.authorizeList = ["search"];
        }
        if(type === 'public') {
            publicSettingEntity = obj;
        }else if(type === 'user') {
            usersSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    usersSettingEntities[index] = obj;
                    if($("input[value='download-user"+index+"']").is(':checked')){
                        obj.authorizeList.forEach(authorizeListItem=>{
                            $("input[value='"+authorizeListItem+"-user"+index+"']").prop("checked", true);
                        })
                    }
                }
            })
        }else if(type === 'department') {
            departmentSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    departmentSettingEntities[index] = obj;
                    if($("input[value='download-department"+index+"']").is(':checked')){
                        obj.authorizeList.forEach(authorizeListItem=>{
                            $("input[value='"+authorizeListItem+"-department"+index+"']").prop("checked", true);
                        })
                    }
                }
            })
        }else if(type === 'group') {
            groupsSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    groupsSettingEntities[index] = obj;
                    if($("input[value='download-group"+index+"']").is(':checked')){
                        obj.authorizeList.forEach(authorizeListItem=>{
                            $("input[value='"+authorizeListItem+"-group"+index+"']").prop("checked", true);
                        })
                    }
                }
            })
        }
    }
    //点击可查看逻辑
    function clickViewCheckBox(obj,type){
        if(!obj.authorizeList || (obj.authorizeList).indexOf("view") === -1){
            obj.authorizeList = ["search","view"];
        }else if((obj.authorizeList).indexOf("search") !== -1){
            obj.authorizeList = ["search"];
        }
        if(type === 'public') {
            publicSettingEntity = obj;
            if($("input[value='view']").is(':checked')){
                obj.authorizeList.forEach(authorizeListItem=>{
                    $("input[value='"+authorizeListItem+"']").prop("checked", true);
                })
            }else {
                $("input[value='edit']").prop("checked", false);
            }
        }else if(type === 'user') {
            usersSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    usersSettingEntities[index] = obj;
                    if($("input[value='view-user"+index+"']").is(':checked')){
                        obj.authorizeList.forEach(authorizeListItem=>{
                            $("input[value='"+authorizeListItem+"-user"+index+"']").prop("checked", true);
                            $("input[value='edit-user"+index+"']").prop("checked", false);
                        })
                    }else {
                        $("input[value='edit-user"+index+"']").prop("checked", false);
                    }
                }
            })
        }else if(type === 'department') {
            departmentSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    departmentSettingEntities[index] = obj;
                    if($("input[value='view-department"+index+"']").is(':checked')){
                        obj.authorizeList.forEach(authorizeListItem=>{
                            $("input[value='"+authorizeListItem+"-department"+index+"']").prop("checked", true);
                            $("input[value='edit-department"+index+"']").prop("checked", false);
                        })
                    }else {
                        $("input[value='edit-department"+index+"']").prop("checked", false);
                    }
                }
            })
        }else if(type === 'group') {
            groupsSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    groupsSettingEntities[index] = obj;
                    if($("input[value='view-group"+index+"']").is(':checked')){
                        obj.authorizeList.forEach(authorizeListItem=>{
                            $("input[value='"+authorizeListItem+"-group"+index+"']").prop("checked", true);
                            $("input[value='edit-group"+index+"']").prop("checked", false);
                        })
                    }else {
                        $("input[value='edit-group"+index+"']").prop("checked", false);
                    }
                }
            })
        }
    }
    //点击可编辑逻辑
    function clickEditCheckBox(obj,type){
        if(!obj.authorizeList || (obj.authorizeList).indexOf("edit") === -1){
            obj.authorizeList = ["search","view","edit"];
        }else if((obj.authorizeList).indexOf("view") !== -1){
            obj.authorizeList = ["search","view"];
        }
        if(type === 'public') {
            publicSettingEntity = obj;
            if($("input[value='edit']").is(':checked')){
                obj.authorizeList.forEach(authorizeListItem=>{
                    $("input[value='"+authorizeListItem+"']").prop("checked", true);
                })
            }   
        }else if(type === 'user') {
            usersSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    usersSettingEntities[index] = obj;
                }
                if($("input[value='edit-user"+index+"']").is(':checked')){
                    obj.authorizeList.forEach(authorizeListItem=>{
                        $("input[value='"+authorizeListItem+"-user"+index+"']").prop("checked", true);
                    })
                }
            })
        }else if(type === 'department') {
            departmentSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    departmentSettingEntities[index] = obj;
                }
                if($("input[value='edit-department"+index+"']").is(':checked')){
                    obj.authorizeList.forEach(authorizeListItem=>{
                        $("input[value='"+authorizeListItem+"-department"+index+"']").prop("checked", true);
                    })
                }
            })
        }else if(type === 'group') {
            groupsSettingEntities.forEach((item,index)=>{
                if(item.entityName === obj.entityName) {
                    groupsSettingEntities[index] = obj;
                }
                if($("input[value='edit-group"+index+"']").is(':checked')){
                    obj.authorizeList.forEach(authorizeListItem=>{
                        $("input[value='"+authorizeListItem+"-group"+index+"']").prop("checked", true);
                    })
                }
            })
        }
    }
    
    // 选择资源类型  查询资源
    function onSelectResourcesType(){
        iPortal = new L.supermap.iPortal(iPortalUrl);
        let type = $("#typeSelect").val();
        resourceType = type;
        queryParams = new L.supermap.iPortalQueryParam({
            resourceType: type,
            searchType:'MY_RES',
            pageSize: 15,
            currentPage: 1
        });
        queryResouces(queryParams);
    }
</script>
</body>
</html>